using System;
using System.Collections.Generic;
using System.Text;
using Db4o.Framework.Business;
using Db4o.Framework.Configuration;
namespace Db4o.Framework
{
    internal class LocalDatabaseStrategy : ConnexionStrategy
    {
        protected static log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private string databaseFile;

        public string DatabaseFile
        {
            get { return databaseFile; }
            set { databaseFile = value; }
        }
        public LocalDatabaseStrategy(string file)
        {
            DatabaseFile = file;
        }

        public override void Connect()
        {
            Connect(DatabaseFile);
        }
        public void Connect(string database)
        {
            Connect(database, false);
        }
        public void Connect(string database, bool overridefile)
        {
            logger.DebugFormat("Load database [{0}]", database);

            if (BusinessManager.Instance.BusinessAssembly == null)
            {
                ExceptionManager.Instance.ThrowFatalLogException("CoreInitializationException", "Assembly was not specified try to configure the engine");
            }
            else
            {
                DataManager.Instance.OpenDatabase(database, overridefile);
            }
        }
    }
}
